from PyQt5 import sip
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction
from qdarkstyle import load_stylesheet_pyqt5
from U_Real2Local_Dialog import Realtime_view
from U_Calculate_Dialog import Main_Window
from Cover_Dialog import Cover
from U_SetDialog import Set_theme
from U_Calculation_Stokes import Calculation_Stokes


class Set_Menu_MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(Set_Menu_MainWindow, self).__init__(parent)
        self.widget_set = None
        self.widget_cover = None

        self.setWindowTitle("天空偏振光分布模式仿真与探测系统")
        self.resize(873, 702)
        self.widget = Cover()
        self.setCentralWidget(self.widget)

        Menu_Bar = self.menuBar()
        self.Menu = Menu_Bar.addMenu("菜单栏")
        self.Cover_Action = QAction("主页")
        self.Set_Action = QAction("设置")
        self.StokesSimulation_Action = QAction("Stokes")
        self.LocalSimulation_Action = QAction("探测")
        self.CalcuSimulation_Action = QAction("计算")
        self.Quite_System_Action = QAction("退出")

        self.Menu.addAction(self.Cover_Action)
        self.Menu.addAction(self.Set_Action)
        self.Menu.addAction(self.StokesSimulation_Action)
        self.Menu.addAction(self.LocalSimulation_Action)
        self.Menu.addAction(self.CalcuSimulation_Action)
        self.Menu.addAction(self.Quite_System_Action)

        self.Cover_Action.setEnabled(False)
        self.Set_Action.setEnabled(True)
        self.StokesSimulation_Action.setEnabled(True)
        self.LocalSimulation_Action.setEnabled(False)
        self.CalcuSimulation_Action.setEnabled(False)
        self.Quite_System_Action.setEnabled(True)
        # 信号与槽
        self.widget.IsRealsimulation_signal.connect(self.IsSimulation_Dialog)
        self.widget.IsCalculat_signal.connect(self.IsCalculate_Dialog)
        self.widget.IsStokes_signal.connect(self.IsStokes_Dialog)
        self.Menu.triggered[QAction].connect(self.Menu_ChuFa)
    # 太阳位置计算界面
    def IsCalculate_Dialog(self):
        self.widget = Main_Window()
        self.setCentralWidget(self.widget)
        self.setWindowTitle("天空偏振光分布模式仿真与探测系统")
        self.Cover_Action.setEnabled(True)
        self.StokesSimulation_Action.setEnabled(True)
        self.LocalSimulation_Action.setEnabled(True)
        self.CalcuSimulation_Action.setEnabled(False)
        self.Quite_System_Action.setEnabled(True)
    # 仿生偏振视觉感知与偏振模式重绘
    def IsSimulation_Dialog(self):
        self.widget = Realtime_view()
        self.setCentralWidget(self.widget)
        self.setWindowTitle("天空偏振光分布模式仿真与探测系统")
        self.Cover_Action.setEnabled(True)
        self.StokesSimulation_Action.setEnabled(True)
        self.LocalSimulation_Action.setEnabled(False)
        self.CalcuSimulation_Action.setEnabled(True)
        self.Quite_System_Action.setEnabled(True)
    # Stokes矢量计算界面
    def IsStokes_Dialog(self):
        self.widget = Calculation_Stokes()
        self.setCentralWidget(self.widget)
        self.setWindowTitle("天空偏振光分布模式仿真与探测系统")
        self.Cover_Action.setEnabled(True)
        self.StokesSimulation_Action.setEnabled(True)
        self.LocalSimulation_Action.setEnabled(False)
        self.CalcuSimulation_Action.setEnabled(True)
        self.Quite_System_Action.setEnabled(True)
    # 设置主题
    def IsSetTheme_Dialog(self):
        if self.widget_set.label1.isChecked():
            self.setStyleSheet('''QWidget{background-color:rgb(0, 0, 0);}''')
        elif self.widget_set.label2.isChecked():
            self.setStyleSheet('''QWidget{background-color:rgb(49, 54, 59);}''')
        else:
            self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
    # 菜单栏选项跳转界面
    def Menu_ChuFa(self, q):
        if q.text() == "主页":
            if self.widget == Main_Window():
                sip.delete(self.widget)
            self.widget_cover = Cover()
            self.setCentralWidget(self.widget_cover)
            self.Cover_Action.setEnabled(False)
            self.LocalSimulation_Action.setEnabled(False)
            self.CalcuSimulation_Action.setEnabled(False)
            self.Quite_System_Action.setEnabled(True)
            self.widget_cover.IsCalculat_signal.connect(self.IsCalculate_Dialog)
            self.widget_cover.IsRealsimulation_signal.connect(self.IsSimulation_Dialog)
        if q.text() == "设置":
            self.widget_set = Set_theme()
            self.widget_set.show()
            self.widget_set.IsSetTheme_signal.connect(self.IsSetTheme_Dialog)
            self.Cover_Action.setEnabled(True)
            self.StokesSimulation_Action.setEnabled(True)
            self.LocalSimulation_Action.setEnabled(False)
            self.CalcuSimulation_Action.setEnabled(False)
            self.Quite_System_Action.setEnabled(True)
        if q.text() == "Stokes":
            self.widget = Calculation_Stokes()
            self.setCentralWidget(self.widget)
            self.Cover_Action.setEnabled(True)
            self.StokesSimulation_Action.setEnabled(True)
            self.LocalSimulation_Action.setEnabled(False)
            self.CalcuSimulation_Action.setEnabled(False)
            self.Quite_System_Action.setEnabled(True)
            self.widget.IsStokes_signal.connect(self.IsStokes_Dialog)
        if q.text() == "计算":
            self.widget = Main_Window()
            self.setCentralWidget(self.widget)
            self.Cover_Action.setEnabled(True)
            self.StokesSimulation_Action.setEnabled(True)
            self.LocalSimulation_Action.setEnabled(True)
            self.CalcuSimulation_Action.setEnabled(False)
            self.Quite_System_Action.setEnabled(True)
            self.widget.IsCalculat_signal.connect(self.IsCalculate_Dialog)
        if q.text() == "探测":
            self.widget = Realtime_view()
            self.setCentralWidget(self.widget)
            self.Cover_Action.setEnabled(True)
            self.StokesSimulation_Action.setEnabled(True)
            self.LocalSimulation_Action.setEnabled(False)
            self.CalcuSimulation_Action.setEnabled(True)
            self.Quite_System_Action.setEnabled(True)
            self.widget.IsRealsimulation_signal.connect(self.IsSimulation_Dialog)
        if q.text() == "退出":
            QApp = QApplication.instance()
            QApp.quit()


if __name__ == "__main__":
    from sys import argv, exit
    app = QApplication(argv)
    app.setStyleSheet(load_stylesheet_pyqt5())
    mainWindow = Set_Menu_MainWindow()
    mainWindow.show()
    exit(app.exec_())
